<template>
  <div class="payment-wrapper">
    <div class="top">
      <div class="title-wrapper">
        <div class="title">短信配置</div>
      </div>
      <el-button type="primary" size="medium" @click="save">保存</el-button>
    </div>
    <div class="content">
      <div class="setting-box" style="margin-top: 20px; width: 500px">
        <el-form
          ref="ruleForm"
          :model="ruleForm"
          :rules="rules"
          label-width="180px"
          class="demo-ruleForm"
        >
          <el-form-item label="签名名称:" prop="sign_name">
            <el-input
              v-model="ruleForm.sign_name"
              size="medium"
              style="width: 300px"
              placeholder="请输入签名名称"
            />
          </el-form-item>
          <el-form-item label="AccessKeyId：" prop="accesskeyid">
            <el-input
              v-model="ruleForm.accesskeyid"
              size="medium"
              style="width: 300px"
              placeholder="请输入accesskeyid"
            />
          </el-form-item>
          <el-form-item label="AccessKeySecret：" prop="accesskeysecret">
            <el-input
              v-model="ruleForm.accesskeysecret"
              size="medium"
              style="width: 300px"
              placeholder="请输入accesskeysecret"
            />
          </el-form-item>
          <el-form-item label="模板Code：" prop="templat_code">
            <el-input v-model="ruleForm.templat_code" type="textarea" placeholder="请输入模板code" style="width: 300px;height: 300px" />
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
import { setMessage, getProtocal } from './../../api/platform-setting'
const ERR_OK = 200
export default {
  data() {
    return {
      ruleForm: {
        sign_name: '',
        accesskeyid: '',
        accesskeysecret: '',
        templat_code: ''
      },
      rules: {
        sign_name: [{ required: true, message: '请输入签名名称', trigger: 'blur' }],
        accesskeyid: [
          { required: true, message: '请输入accesskeyid', trigger: 'blur' }
        ],
        accesskeysecret: [{ required: true, message: '请输入accesskeysecret', trigger: 'blur' }],
        templat_code: [{ required: true, message: '请输入模板Code', trigger: 'blur' }]
      }
    }
  },
  created() {
    getProtocal()
      .then(res => {
        if (res.code === ERR_OK) {
          console.log(res)
          this.ruleForm.sign_name = res.data.smsConfig.sign_name
          this.ruleForm.accesskeyid = res.data.smsConfig.accesskeyid
          this.ruleForm.accesskeysecret = res.data.smsConfig.accesskeysecret
          this.ruleForm.templat_code = res.data.smsConfig.templat_code
        }
      })
      .catch(err => {
        console.log(err)
      })
  },
  methods: {
    save() {
      this.$refs['ruleForm'].validate(valid => {
        if (valid) {
          this._setMessage(this.ruleForm)
        } else {
          return false
        }
      })
    },
    _setMessage({ accesskeyid, accesskeysecret, sign_name, templat_code }) {
      setMessage({ accesskeyid, accesskeysecret, sign_name, templat_code })
        .then(res => {
          if (res.code === ERR_OK) {
            console.log(res)
            this.$message({
              message: res.message,
              showClose: true,
              type: 'success'
            })
          }
        })
        .catch(err => {
          console.log(err)
        })
    }
  }
}
</script>
<style lang="scss" scoped>
// @import "@/styles/el-button.scss";
.payment-wrapper {
  padding: 0 20px;
  box-sizing: border-box;
  .top {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    .title-wrapper {
      display: flex;
      align-content: center;
      .title {
        height: 44px;
        line-height: 44px;
        color: rgba(68, 68, 68, 1);
        font-size: 18px;
        font-family: Roboto;
        font-weight: bold;
        cursor: pointer;
      }
    }
  }
}
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background-color: #eff7ff;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  height: 50px;
  line-height: 50px;
  text-align: center;
  margin-right: 10px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
</style>
